/**
 *   api
 *  @module code/api/file
 *  @author coder
 */
import ajax from '@/utils/HttpUtil'
import { baseUrl as API_HOST } from '/env'

/**
 * 文件下载
 * @const
 * @type {String}
 * @default  '[API_HOST]/file/downloadFile/:id'
 */
export const GET_DOWNLOAD_FILE_ID = API_HOST + '/file/downloadFile/:id'

/**
 * 文件下载
 * @param {string|number} id Url参数id
 * @param {object} [data] 发送键值对数据
 * @param {object} [options] ajax参数选项
 * @returns {Promise}
 */
export function getDownloadFileId(id, data, options) {
  return ajax({
    method: 'get',
    params: {
      id
    },
    data: data,
    url: GET_DOWNLOAD_FILE_ID,
    ...options
  })
}

/**
 * 文件关联更新
 * @const
 * @type {String}
 * @default  '[API_HOST]/file/updateRelate'
 */
export const POST_FILE_UPDATE_RELATE = API_HOST + '/file/updateRelate'

/**
 * 文件关联更新
 * @param {object} [data] 发送键值对数据
 * @param {object} [options] ajax参数选项
 * @returns {Promise}
 */
export function postFileUpdateRelate(data, options) {
  return ajax({
    method: 'post',
    data: data,
    url: POST_FILE_UPDATE_RELATE,
    ...options
  })
}

/**
 * 单个上传文件
 * @const
 * @type {String}
 * @default  '[API_HOST]/file/uploadFile'
 */
export const POST_FILE_UPLOAD_FILE = API_HOST + '/file/uploadFile'

/**
 * 单个上传文件
 * @param {object} [data] 发送键值对数据
 * @param {object} [options] ajax参数选项
 * @returns {Promise}
 */
export function postFileUploadFile(data, options) {
  return ajax({
    method: 'post',
    data: data,
    url: POST_FILE_UPLOAD_FILE,
    ...options
  })
}

/**
 * 批量上传文件
 * @const
 * @type {String}
 * @default  '[API_HOST]/file/uploadMultipleFiles'
 */
export const POST_FILE_UPLOAD_MULTIPLE_FILES = API_HOST + '/file/uploadMultipleFiles'

/**
 * 批量上传文件
 * @param {object} [data] 发送键值对数据
 * @param {object} [options] ajax参数选项
 * @returns {Promise}
 */
export function postFileUploadMultipleFiles(data, options) {
  return ajax({
    method: 'post',
    data: data,
    url: POST_FILE_UPLOAD_MULTIPLE_FILES,
    ...options
  })
}

/**
 * 单个上传文件->云服务器
 * @const
 * @type {String}
 * @default  '[API_HOST]/file/uploadOss'
 */
export const POST_FILE_UPLOAD_OSS = API_HOST + '/file/uploadOss'

/**
 * 单个上传文件->云服务器
 * @param {object} [data] 发送键值对数据
 * @param {object} [options] ajax参数选项
 * @returns {Promise}
 */
export function postFileUploadOss(data, options) {
  return ajax({
    method: 'post',
    data: data,
    url: POST_FILE_UPLOAD_OSS,
    ...options
  })
}

/**
 * WangEditorFile-图片上传
 * @const
 * @type {String}
 * @default  '[API_HOST]/file/uploadWangEditorFile'
 */
export const POST_FILE_UPLOAD_WANG_EDITOR_FILE = API_HOST + '/file/uploadWangEditorFile'

/**
 * WangEditorFile-图片上传
 * @param {object} [data] 发送键值对数据
 * @param {object} [options] ajax参数选项
 * @returns {Promise}
 */
export function postFileUploadWangEditorFile(data, options) {
  return ajax({
    method: 'post',
    data: data,
    url: POST_FILE_UPLOAD_WANG_EDITOR_FILE,
    ...options
  })
}
